﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using MvcEngine.Core;
using MvcEngine.Mvc.Models.ViewModels;
using MvcEngine.Mvc.StarterSite.Controllers;
using MvcEngine.Core.Localization;
using MvcEngine.Mvc.Extensions;
using MvcEngine.HtmlText.Repositories;
using MvcEngine.HtmlText.Models;
using MvcEngine.HtmlText.Models.Entities;
using MvcEngine.Mvc.Filters;
using MvcEngine.Mvc;
using System.Web;
using MvcEngine.Core.Exceptions;
using MvcEngine.Core.Extensions;
using System.IO;
using MvcEngine.Core.Helpers;
using MvcEngine.Core.Configuration;
using MvcEngine.HtmlText.Components.Extensions;
using System.Globalization;
using MvcEngine.Mvc.Controllers;

namespace MvcEngine.HtmlText.StarterSite.Controllers
{
    public class TextController : SubController
    {
        public MvcEngineModelItem<HtmlTextViewModel> Index(int ctrId, int? ctrReferenceId)
        {
            HtmlTextItem item = null;
            if (ctrReferenceId.HasValue)
                item = IoC.Resolve<IHtmlTextRepository>().Get(ctrReferenceId.Value);
            else
                item = IoC.Resolve<IHtmlTextRepository>().Get(ctrId);

            string content = ResourceReader.Current.GetString("NoText");

            if (item != null)
                content = item.Text;

            return new MvcEngineModelItem<HtmlTextViewModel>() { Item = new HtmlTextViewModel() { ContainerId = ctrId, Content = content } };
        }
    }
}
